from collections import Counter

from app.monitor_doris.utils import message_segment

__all__ = ['character_log_output']


def character_log_output(message: list) -> str:
    """
    :param message: 日志列表
    :return: 输出特征日志
    """
    character_log = ""
    analyze_messages = []
    raw_data = {}
    segment_data = {}
    for index, line in enumerate(message):
        segment_data[index] = message_segment(line)
        raw_data[index] = line
        analyze_messages.extend(segment_data[index])
    total_counter_res = Counter(analyze_messages)

    min_score = 0
    for index, line in segment_data.items():
        counter_res = {k: v for k, v in total_counter_res.items() if k in line}
        score = sum(counter_res.values())
        if score > min_score:
            min_score = score
            character_log = raw_data[index]
    return character_log[:400]
